package com.vst.orm.dao.hibernate.original;

import com.vst.orm.dao.hibernate.*;
import com.vst.orm.search.ExampleOptions;
import com.vst.orm.search.Filter;
import com.vst.orm.search.ISearch;
import com.vst.orm.search.SearchResult;

import java.io.Serializable;
import java.util.List;
import org.hibernate.NonUniqueResultException;

public class GeneralDAOImpl extends HibernateBaseDAO implements GeneralDAO {
	public void create(Object object) {
		_save(object);
	}

	public boolean createOrUpdate(Object object) {
		Serializable id = getMetaDataUtil().getId(object);
		if ((id == null) || (new Long(0L).equals(id))) {
			create(object);
			return true;
		}
		update(object);
		return false;
	}

	public boolean deleteById(Class<?> klass, Serializable id) {
		return _deleteById(klass, id);
	}

	public boolean deleteEntity(Object object) {
		return _deleteEntity(object);
	}

	public <T> T fetch(Class<T> klass, Serializable id) {
		return (T) _get(klass, id);
	}

	public <T> List<T> fetchAll(Class<T> klass) {
		return _all(klass);
	}

	public void update(Object object) {
		_update(new Object[] { object });
	}

	public List search(ISearch search) {
		return _search(search);
	}

	public int count(ISearch search) {
		return _count(search);
	}

	public SearchResult searchAndCount(ISearch search) {
		return _searchAndCount(search);
	}

	public void flush() {
		_flush();
	}

	public boolean isConnected(Object object) {
		return _sessionContains(object);
	}

	public Object searchUnique(ISearch search) throws NonUniqueResultException {
		return _searchUnique(search);
	}

	public void refresh(Object object) {
		_refresh(new Object[] { object });
	}

	public Filter getFilterFromExample(Object example) {
		return _getFilterFromExample(example);
	}

	public Filter getFilterFromExample(Object example, ExampleOptions options) {
		return _getFilterFromExample(example, options);
	}
}
